package api

import (
	"gitee.com/DengAnbang/Wefore/src/bean"
	"gitee.com/DengAnbang/Wefore/src/dbops"
	"gitee.com/DengAnbang/Wefore/src/fun"
	"gitee.com/DengAnbang/goutils/httpUtils"
	"net/http"
)

/**
* showdoc
* @catalog 接口文档/文件夹树
* @title 创建节点
* @description 创建节点的接口
* @method socket type=401
* @url /pc/file/treeNode/create
* @param userId 必选 string 创建人的id
* @param nodeName 必选 string 节点名
* @param nodeParentId 选填 string 父节点ID(不填就是新树)
* @return {"code":0,"type":0,"message":"","debug_message":"","data":FileTreeBean}
* @remark nodeParentId不填就是新树
* @number 2
 */
func FileTreeNodeCreateHttp(_ http.ResponseWriter, r *http.Request) error {
	userId := httpUtils.GetValueFormRequest(r, "userId")
	nodeName := httpUtils.GetValueFormRequest(r, "nodeName")
	nodeParentId := httpUtils.GetValueFormRequest(r, "nodeParentId")
	node, err := dbops.FileTreeNodeCreate(userId, nodeName, nodeParentId, true)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(node)
}
func FileTreeNodeCreateSocket(parameters map[string]interface{}) error {
	userId := fun.GetString(parameters, "userId")
	nodeName := fun.GetString(parameters, "nodeName")
	nodeParentId := fun.GetString(parameters, "nodeParentId")
	node, err := dbops.FileTreeNodeCreate(userId, nodeName, nodeParentId, true)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(node)
}

/**
* showdoc
* @catalog 接口文档/文件夹树
* @title 删除节点
* @description 删除节点的接口
* @method socket type=402
* @url /pc/file/treeNode/delete
* @param nodeId 必选 nodeId 节点ID
* @return {"code":0,"type":0,"message":"","debug_message":"","data":"删除成功"}
* @remark
* @number 2
 */
func FileTreeNodeDeleteHttp(_ http.ResponseWriter, r *http.Request) error {
	nodeId := httpUtils.GetValueFormRequest(r, "nodeId")
	err := dbops.FileTreeNodeDeleteAll(nodeId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage("删除成功")
}
func FileTreeNodeDeleteSocket(parameters map[string]interface{}) error {
	nodeId := fun.GetString(parameters, "nodeId")
	err := dbops.FileTreeNodeDeleteAll(nodeId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage("删除成功")
}

/**
* showdoc
* @catalog 接口文档/文件夹树
* @title 修改节点
* @description 修改节点的接口(仅仅修改名字)
* @method socket type=403
* @url /pc/file/treeNode/update
* @param nodeId 必选 string 节点ID
* @param nodeName 必选 string 节点的新名字
* @return {"code":0,"type":0,"message":"","debug_message":"","data":"修改成功"}
* @remark 修改的时候，必须两个值都传
* @number 3
 */
func FileTreeNodeUpdateHttp(_ http.ResponseWriter, r *http.Request) error {
	nodeId := httpUtils.GetValueFormRequest(r, "nodeId")
	nodeName := httpUtils.GetValueFormRequest(r, "nodeName")
	err := dbops.FileTreeNodeUpdate(nodeId, nodeName)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage("修改成功")
}
func FileTreeNodeUpdateSocket(parameters map[string]interface{}) error {
	nodeId := fun.GetString(parameters, "nodeId")
	nodeName := fun.GetString(parameters, "nodeName")
	err := dbops.FileTreeNodeUpdate(nodeId, nodeName)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage("修改成功")
}

/**
* showdoc
* @catalog 接口文档/文件夹树
* @title 查询节点(一层)
* @description 查询节点的接口(仅仅查询当前节点的子)
* @method socket type=404
* @url /pc/file/treeNode/select/child
* @param nodeId 必选 nodeId 节点ID
* @return {"code":0,"type":0,"message":"","debug_message":"","data":[]FileTreeBean}
* @remark
* @number 4
 */
func FileTreeChildNodeSelectHttp(_ http.ResponseWriter, r *http.Request) error {
	nodeId := httpUtils.GetValueFormRequest(r, "nodeId")
	beans, err := dbops.FileTreeChildNodeSelect(nodeId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(beans)
}
func FileTreeChildNodeSelectSocket(parameters map[string]interface{}) error {
	nodeId := fun.GetString(parameters, "nodeId")
	beans, err := dbops.FileTreeChildNodeSelect(nodeId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(beans)
}

/**
* showdoc
* @catalog 接口文档/文件夹树
* @title 查询所有文件夹(所有子)
* @description 查询节点的接口(查询当前节点的所有子)
* @method socket type=405
* @url /pc/file/treeNode/select/child/all
* @param nodeId 必选 string 节点ID,根节点的ID就是这个用户的id
* @return {"code":0,"type":0,"message":"","debug_message":"","data":[]FileTreeBean}
* @remark 如果是查询个人文件夹 nodeId就是自己的id，如果是项目的文件夹，就是项目的id
* @number 5
 */
func FileTreeChildNodeSelectAllHttp(_ http.ResponseWriter, r *http.Request) error {
	nodeId := httpUtils.GetValueFormRequest(r, "nodeId")
	beans, err := dbops.FileTreeChildNodeSelectAll(nodeId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(beans)
}
func FileTreeChildNodeSelectAllSocket(parameters map[string]interface{}) error {
	nodeId := fun.GetString(parameters, "nodeId")
	beans, err := dbops.FileTreeChildNodeSelectAll(nodeId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(beans)
}

/**
* showdoc
* @catalog 接口文档/文件夹树
* @title 将文件添加到文件夹
* @description 将文件添加到文件夹
* @method socket type=406
* @url /pc/file/treeNode/file/add
* @param nodeId 必选 string 节点ID
* @param filePath 必选 string 文件的路径（调用上传文件接口后，返回的）
* @param fileId 必选 string 文件的id
* @param workTime 必选 string 文件的工时
* @return {"code":0,"type":0,"message":"","debug_message":"","data":"添加成功"}
* @remark
* @number 6
 */
func FileTreeFileAddHttp(_ http.ResponseWriter, r *http.Request) error {
	nodeId := httpUtils.GetValueFormRequest(r, "nodeId")
	filePath := httpUtils.GetValueFormRequest(r, "filePath")
	fileId := httpUtils.GetValueFormRequest(r, "fileId")
	workTime := httpUtils.GetValueFormRequest(r, "workTime")
	err := dbops.FileTreeFileAdd(nodeId, filePath, fileId, workTime)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage("添加成功")
}
func FileTreeFileAddSocket(parameters map[string]interface{}) error {
	nodeId := fun.GetString(parameters, "nodeId")
	filePath := fun.GetString(parameters, "filePath")
	fileId := fun.GetString(parameters, "fileId")
	workTime := fun.GetString(parameters, "workTime")
	err := dbops.FileTreeFileAdd(nodeId, filePath, fileId, workTime)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage("添加成功")
}

/**
* showdoc
* @catalog 接口文档/文件夹树
* @title 查询文件夹下面的文件
* @description 查询节点的接口(查询当前节点的所有子)
* @method socket type=407
* @url /pc/file/treeNode/file/select
* @param nodeId 必选 string 节点ID,根节点的ID就是这个用户的id
* @return {"code":0,"type":0,"message":"","debug_message":"","data":[]FileBean}
* @remark
* @number 7
 */
func FileTreeFileSelectHttp(_ http.ResponseWriter, r *http.Request) error {
	nodeId := httpUtils.GetValueFormRequest(r, "nodeId")
	beans, err := dbops.FileTreeFileSelect(nodeId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(beans)
}
func FileTreeFileSelectSocket(parameters map[string]interface{}) error {
	nodeId := fun.GetString(parameters, "nodeId")
	beans, err := dbops.FileTreeFileSelect(nodeId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(beans)
}

/**
* showdoc
* @catalog 接口文档/文件夹树
* @title 委托别人处理
* @description 委托别人处理
* @method socket type=408
* @url /pc/file/treeNode/file/commissioned
* @param fileId 必选 string 文件的id
* @param filePath 必选 string 文件的路径（调用上传文件接口后，返回的）
* @param userId 必选 string 被委托人的id
* @param workTime 必选 string 文件的工时
* @return {"code":0,"type":0,"message":"","debug_message":"","data":"委托成功"}
* @remark
* @number 8
 */
func FileTreeFileCommissionedHttp(_ http.ResponseWriter, r *http.Request) error {
	fileId := httpUtils.GetValueFormRequest(r, "fileId")
	filePath := httpUtils.GetValueFormRequest(r, "filePath")
	userId := httpUtils.GetValueFormRequest(r, "userId")
	workTime := httpUtils.GetValueFormRequest(r, "workTime")
	toUserId := httpUtils.GetValueFormRequest(r, "toUserId")
	err := dbops.FileTreeFileCommissioned(fileId, filePath, userId, toUserId, workTime)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage("委托成功")
}
func FileTreeFileCommissionedSocket(parameters map[string]interface{}) error {
	fileId := fun.GetString(parameters, "fileId")
	filePath := fun.GetString(parameters, "filePath")
	userId := fun.GetString(parameters, "userId")
	workTime := fun.GetString(parameters, "workTime")
	toUserId := fun.GetString(parameters, "toUserId")
	err := dbops.FileTreeFileCommissioned(fileId, filePath, userId, toUserId, workTime)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage("委托成功")
}

/**
* showdoc
* @catalog 接口文档/文件夹树
* @title 查询委托流程
* @description 查询委托流程
* @method socket type=409
* @url /pc/file/treeNode/file/commissioned/select
* @param fileId 必选 string 文件的id
* @return {"code":0,"type":0,"message":"","debug_message":"","data":[]Commissioned}
* @remark
* @number 9
 */
func FileTreeFileCommissionedSelectHttp(_ http.ResponseWriter, r *http.Request) error {
	fileId := httpUtils.GetValueFormRequest(r, "fileId")
	commissioneds, err := dbops.CommissionedFlowSelect(fileId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(commissioneds)
}
func FileTreeFileCommissionedSelectSocket(parameters map[string]interface{}) error {
	fileId := fun.GetString(parameters, "fileId")
	commissioneds, err := dbops.CommissionedFlowSelect(fileId)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(commissioneds)
}
